package com.yuelan.apartment.controller;

import com.yuelan.apartment.domain.ApaNotice;
import com.yuelan.apartment.service.ApaNoticeService;
import com.yuelan.common.annotation.Log;
import com.yuelan.common.core.controller.BaseController;
import com.yuelan.common.core.domain.AjaxResult;
import com.yuelan.common.core.page.TableDataInfo;
import com.yuelan.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 通知与公告
 * @Author: ZhaoYi
 * @date: 24-6-29 19:55
 */
@RestController
@RequestMapping("notice")
public class ApaNoticeController extends BaseController {

    @Autowired
    private ApaNoticeService apaNoticeService;


    @PostMapping
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    @Log(title = "发布公告", businessType = BusinessType.INSERT)
    public AjaxResult publish(@RequestBody ApaNotice apaNotice) {
        return toAjax(apaNoticeService.publishNotice(apaNotice));
    }


    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    public AjaxResult view(@PathVariable Long id) {
        return success(apaNoticeService.view(id));
    }


    @GetMapping("/list")
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    public TableDataInfo noticeList(int pageNum, int pageSize) {
        return apaNoticeService.noticeList(pageNum, pageSize);
    }


    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    @Log(title = "删除公告", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(apaNoticeService.removeNotice(id));
    }


    @PutMapping
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    @Log(title = "编辑公告", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody ApaNotice apaNotice) {
        return toAjax(apaNoticeService.editNotice(apaNotice));
    }
}
